package com.android.NmtMobile;

import com.adroid.NmtMobile.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class NmtMobileActivity extends Activity {	
    private GridView gridview;
    private String[] homeTextArray;
    private Resources res;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //calls resources and gets array of text for grid
        res = getResources();
        homeTextArray  = res.getStringArray(R.array.homegridtext);
        
        //sets up Grid View then calls adapter class to modify for icons and text
        gridview = (GridView) findViewById(R.id.homeGrid);
        gridview.setAdapter(new HomeAdapter(this));
        
        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            	// if Maps was selected
            	if(position == 1)
            	{
            		//creates a new intent to start Campus Maps class
	            	Intent i = new Intent(NmtMobileActivity.this, CampusMaps.class);
	                startActivity(i);
            	}
            }
        });
    }
    
    //adapter class for modifying grid view
    public class HomeAdapter extends BaseAdapter {
    	private Context mContext;

    	public HomeAdapter(Context _mContext) {
			mContext = _mContext;
		}

		@Override
    	public int getCount() {
    		return 5;
    	}

    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    		View grid = convertView;
    	    
    		if ( convertView == null )
            {
               /*we define the view that will display on the grid*/
               
               //Inflate the layout
               LayoutInflater li = getLayoutInflater();
               grid = li.inflate(R.layout.homegrid, null);
               
               // Add text
               TextView tv = (TextView)grid.findViewById(R.id.homeText);
               tv.setText(homeTextArray[position]);
               
               // Add image           
               ImageView iv = (ImageView)grid.findViewById(R.id.homeImage);
               iv.setImageResource(R.drawable.androidmarker);
            }

		   return grid;
    	}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}
    }
}